package com.game.backend.config;

import com.game.backend.common.ErrorResponse;
import com.game.backend.common.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 功能描述
 *
 * @author wanghongqian
 * @date 2023/08/07 16:10
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity handleBusinessException(RuntimeException ex) {
        // 处理业务异常，返回包含错误码和错误信息的响应体
        ex.printStackTrace();
        return ResponseEntity.fail(ex.getMessage());
    }

}
